package pe.edu.ups.studio.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pe.edu.upc.studio.excepcion.DAOExcepcion;
import pe.edu.upc.studio.modelo.Sala;
import pe.edu.upc.studio.negocio.GestionSalaNegocio;

/**
 * Servlet implementation class BuscarSalaServlet
 */
@WebServlet("/BuscarSalaServlet")
public class BuscarSalaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public BuscarSalaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String strSala = request.getParameter("txtSala");
		String strLocal = request.getParameter("txtLocal");
		String strCapacidad = request.getParameter("txtCapacidad");
		int intCapacidad =0;
			if (strCapacidad.trim().equals("")) {
				intCapacidad=0;
			}else{
				intCapacidad = Integer.parseInt(strCapacidad);
			}		
		GestionSalaNegocio dao = new GestionSalaNegocio();
		try {
			Collection<Sala> lista = new ArrayList<Sala>();
			lista = dao.BuscarSalaArmado(strSala, strLocal, intCapacidad);
			request.setAttribute("listadosala", lista);
			RequestDispatcher rd = request.getRequestDispatcher("buscarsalas.jsp");
			rd.forward(request, response);
		} catch (DAOExcepcion e) {
			String msj =e.getMessage();
			System.err.println(msj);
			RequestDispatcher rd = request.getRequestDispatcher("/error.jsp?error=" + msj);
			rd.forward(request, response);
		}
	}

}
